﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf_Tool_ZC.util;

namespace Wpf_Tool_ZC
{
    /// <summary>
    /// Interaction logic for Wnd_String.xaml
    /// </summary>
    public partial class Wnd_String : Window
    {
        Wnd_Log FwndLog = null;

        public Wnd_String(Wnd_Log _wndLog)
        {
            InitializeComponent();

            FwndLog = _wndLog;
        }

        private void Url01_Click(object sender, RoutedEventArgs e)
        {
            // 冰雪奇缘1国语版 在"天龙影院" 的视频下载地址 (ts文件)
            string str1 = "https://zy.512wx.com/20171130/t3WlcRwl/1200kb/hls/ppvod3719";
            string str2 = ".ts";

            for (int i = 1; i <= 1078; i++)
            {
                string str;
                if (i < 1000)
                    str = i.ToString("000");
                else
                    str = i.ToString();

                //Console.WriteLine(str1 + str + str2);
                FwndLog.MsgAppend_01(str1 + str + str2);
            }
        }

        //https://www.mmicloud.com:65/20190407/WcOf2F3x/2000kb/hls/A01kN5104007.ts
        private void Url02_Click(object sender, RoutedEventArgs e)
        {

            string str1 = "https://www.mmicloud.com:65/20190407/WcOf2F3x/2000kb/hls/A01kN5104";
            string str2 = ".ts";

            for (int i = 1; i <= 82; i++)
            {
                string str;
                if (i < 1000)
                    str = i.ToString("000");
                else
                    str = i.ToString();

                //Console.WriteLine(str1 + str + str2);
                FwndLog.MsgAppend_01(str1 + str + str2);
            }
        }

        //https://new.jsyunbf.com/20180108/KvudKkIx/900kb/hls/aIyM2T5957003.ts
        private void Url03_Click(object sender, RoutedEventArgs e)
        {

            string str1 = "https://new.jsyunbf.com/20180108/KvudKkIx/900kb/hls/aIyM2T5957";
            string str2 = ".ts";

            for (int i = 1; i <= 223; i++)
            {
                string str;
                if (i < 1000)
                    str = i.ToString("000");
                else
                    str = i.ToString();

                //Console.WriteLine(str1 + str + str2);
                FwndLog.MsgAppend_01(str1 + str + str2);
            }
        }



        private void Click_Str03(object sender, RoutedEventArgs e)
        {
            string str = "2676657273696F6E3D306630353035383764313165303463636666373832666534616565646436633126626F6F696E67446174653D323032302D30322D313820485454502F312E310D0A486F73743A206D79637A2E6B696E67646F6E736F66742E636F6D0D0A436F6E6E656374696F6E3A206B6565702D616C6976650D0A436F6E74656E742D4C656E6774683A20320D0A4163636570743A202A2F2A0D0A4F726967696E3A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D0D0A582D5265717565737465642D576974683A20584D4C48747470526571756573740D0A417574686F72697A6174696F6E3A204D79435A20546D464F4F6A41304E7A67794E44646D4F44457A4E44637A4F5463324E7A4A6C595445334D324D355A6D5A6C5A6D45770D0A557365722D4167656E743A204D6F7A696C6C612F352E3020284C696E75783B20416E64726F696420372E303B205265646D69204E6F7465203458204275696C642F4E524439304D3B20777629204170706C655765624B69742F3533372E333620284B48544D4C2C206C696B65204765636B6F292056657273696F6E2F342E30204368726F6D652F36342E302E333238322E313337204D6F62696C65205361666172692F3533372E3336206D79637A2F312E33206B646D79637A2F312E330D0A436F6E74656E742D547970653A206170706C69636174696F6E2F6A736F6E0D0A526566657265723A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D2F6D796368616E677A686F752F4D61736B426F6F6B696E674275792F696E6465782E68746D6C0D0A4163636570742D456E636F64696E673A20677A69702C206465666C6174650D0A4163636570742D4C616E67756167653A207A682D434E2C656E2D55533B713D302E390D0A436F6F6B69653A2042494769705365727665726B6F757A616F2D6E65773D333734313832313132302E32303438302E303030303B204153502E4E45545F53657373696F6E49643D7168653276787867796E6F3377756E33686167326D7476650D0A0D0A7B7D";
            //string str = "504F5354202F4D61736B506F7274616C5765624170692F4D61736B2F4164644D61736B426F6F6B696E673F706861726D61637949643D333226506861726D6163794E616D653D25453625383125393225453625423325423025453425424125424125453625423025393125453525413425413725453825384425414625453625383825424625453525423825423825453525423725394525453925394425393225453625394525414225453425424125384325453525424125393726506861726D616379416464726573733D2545392539322539462545362541352542432545352538432542412545392539442539322545362539452541422545352541332542392545352538462542373125453525384625423725453525393525383625453925393325424126426F6F6B696E67446174653D54756525323046656225323031382532303230323025323030393A35393A3535253230474D542B30383030253230284353542926757569643D303437383234376638313334373339373637326561313733633966666566613026757365724E616D653D2545352539312541382545362539382541352669644E6F3D333230343034313938343035313433343132266D6F62696C653D31333737353231373538312676657273696F6E3D306630353035383764313165303463636666373832666534616565646436633126626F6F696E67446174653D323032302D30322D313820485454502F312E310D0A486F73743A206D79637A2E6B696E67646F6E736F66742E636F6D0D0A436F6E6E656374696F6E3A206B6565702D616C6976650D0A436F6E74656E742D4C656E6774683A20320D0A4163636570743A202A2F2A0D0A4F726967696E3A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D0D0A582D5265717565737465642D576974683A20584D4C48747470526571756573740D0A417574686F72697A6174696F6E3A204D79435A20546D464F4F6A41304E7A67794E44646D4F44457A4E44637A4F5463324E7A4A6C595445334D324D355A6D5A6C5A6D45770D0A557365722D4167656E743A204D6F7A696C6C612F352E3020284C696E75783B20416E64726F696420372E303B205265646D69204E6F7465203458204275696C642F4E524439304D3B20777629204170706C655765624B69742F3533372E333620284B48544D4C2C206C696B65204765636B6F292056657273696F6E2F342E30204368726F6D652F36342E302E333238322E313337204D6F62696C65205361666172692F3533372E3336206D79637A2F312E33206B646D79637A2F312E330D0A436F6E74656E742D547970653A206170706C69636174696F6E2F6A736F6E0D0A526566657265723A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D2F6D796368616E677A686F752F4D61736B426F6F6B696E674275792F696E6465782E68746D6C0D0A4163636570742D456E636F64696E673A20677A69702C206465666C6174650D0A4163636570742D4C616E67756167653A207A682D434E2C656E2D55533B713D302E390D0A436F6F6B69653A2042494769705365727665726B6F757A616F2D6E65773D333734313832313132302E32303438302E303030303B204153502E4E45545F53657373696F6E49643D7168653276787867796E6F3377756E33686167326D7476650D0A0D0A7B7D";
            //string str = "504F5354202F4D61736B506F7274616C5765624170692F4D61736B2F476574506861726D6163794C69737420485454502F312E310D0A486F73743A206D79637A2E6B696E67646F6E736F66742E636F6D0D0A436F6E6E656374696F6E3A206B6565702D616C6976650D0A436F6E74656E742D4C656E6774683A2035340D0A4163636570743A202A2F2A0D0A4F726967696E3A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D0D0A582D5265717565737465642D576974683A20584D4C48747470526571756573740D0A417574686F72697A6174696F6E3A204D79435A20546D464F4F6D51784D444D354E5445354E5451324D6D4D3559544D314E324979597A59334D5745354D3251344F4449310D0A557365722D4167656E743A204D6F7A696C6C612F352E3020284C696E75783B20416E64726F696420372E303B205265646D69204E6F7465203458204275696C642F4E524439304D3B20777629204170706C655765624B69742F3533372E333620284B48544D4C2C206C696B65204765636B6F292056657273696F6E2F342E30204368726F6D652F36342E302E333238322E313337204D6F62696C65205361666172692F3533372E3336206D79637A2F312E33206B646D79637A2F312E330D0A436F6E74656E742D547970653A206170706C69636174696F6E2F6A736F6E0D0A526566657265723A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D2F6D796368616E677A686F752F4D61736B426F6F6B696E674275792F696E6465782E68746D6C0D0A4163636570742D456E636F64696E673A20677A69702C206465666C6174650D0A4163636570742D4C616E67756167653A207A682D434E2C656E2D55533B713D302E390D0A436F6F6B69653A2042494769705365727665726B6F757A616F2D6E65773D333734313832313132302E32303438302E303030303B204153502E4E45545F53657373696F6E49643D7168653276787867796E6F3377756E33686167326D7476650D0A0D0A7B2241726561436F6465223A22222C224B6579776F726473223A22222C2253746F636B44617465223A22323032302D30322D3137227D";

            str = "";
            FwndLog.MsgAppend_01(UtilString.HexStr2ByteArray(str));
        }



        private void Click_Base64_01(object sender, RoutedEventArgs e)
        {
            string str = "恒泰人民大药房";
            Console.WriteLine(UtilString.Base64_Encode(str));
            char c = str[0];
            Console.WriteLine(Convert.ToInt32(c));
            // %E6%81%92%E6%B3%B0%E4%BA%BA%E6%B0%91%E5%A4%A7%E8%8D%AF%E6%88%BF%E5%B8%B8%E5%B7%9E%E9%9D%92%E6%9E%AB%E4%BA%8C%E5%BA%97


            //Encoding encUtf8 = Encoding.GetEncoding("utf8");
            //str.get


            //byte[] big5b = big5.GetBytes("編程無悔！");
            ////关键也就是这句了
            //byte[] gb2312b = Encoding.Convert(big5, gb2312, big5b);

            //string strGb2312 = gb2312.GetString(gb2312b)

            UTF8Encoding utf8 = new UTF8Encoding();
            byte[] encodedBytes = utf8.GetBytes(str);
            Console.WriteLine(Convert.ToInt32(encodedBytes[0]));
            Console.WriteLine(System.Text.Encoding.Default.GetString(encodedBytes));
        }



        

        private void Click_Utf8_01(object sender, RoutedEventArgs e)
        {
            string _str = "abcd";
            char c1 = _str[1];
            char c2 = _str[2];
            string str = "" + _str[1] + _str[2];
            Console.WriteLine(str);


            str = "恒泰人民大药房";
            UTF8Encoding utf8 = new UTF8Encoding();
            byte[] encodedBytes = utf8.GetBytes(str);
            Console.WriteLine(Convert.ToInt32(encodedBytes[0]));
            //Console.WriteLine(System.Text.Encoding.Default.GetString(encodedBytes));
            Console.WriteLine(System.Text.Encoding.UTF8.GetString(encodedBytes));
            //Console.WriteLine(Convert.ToBase64String(encodedBytes));// 求助C# UTF-8 到string转换的问题-CSDN论坛.html(https://bbs.csdn.net/topics/392273205)

            str = "%E6%81%92%E6%B3%B0%E4%BA%BA%E6%B0%91%E5%A4%A7%E8%8D%AF%E6%88%BF%E5%B8%B8%E5%B7%9E%E9%9D%92%E6%9E%AB%E4%BA%8C%E5%BA%97";
            Console.WriteLine(UtilString.DecodeZ_Utf8(str));
        }

        

        private void Click_Utf8_02(object sender, RoutedEventArgs e)
        {
            Console.WriteLine(UtilString.EncodeZ_Utf8("周春"));//   %E5%91%A8%E6%98%A5

            string str = UtilString.EncodeZ_Utf8("周琳茜");
            Console.WriteLine(str);// %E5%91%A8%E7%90%B3%E8%8C%9C

            byte[] bb = System.Text.Encoding.Default.GetBytes(str);
            str = "";
            for (int i = 0; i < bb.Length; i++)
                str += bb[i].ToString("X2");
            FwndLog.MsgAppend_01(UtilString.HexStr2ByteArray(str));
        }

        private void Click_Test01(object sender, RoutedEventArgs e)
        {
            //string str = "周琳茜";
            //str = UtilString.EncodeZ_Utf8(str);
            //Console.WriteLine(str);

            //string str = "%E9%92%9F%E6%A5%BC%E5%8C%BA%E9%83%BD%E5%B8%82%E6%A1%83%E6%BA%90%31%E4%B8%80%32%35%20%E4%BA%BA%E6%B0%91%E5%A4%A7%E8%8D%AF%E6%88%BF";
            //str = UtilString.Str2Hex(str);
            //Console.WriteLine(str);

            ////str = UtilString.HexStr2ByteArray(str);
            ////Console.WriteLine(str);

            string str = "504F5354202F4D61736B506F7274616C5765624170692F4D61736B2F4164644D61736B426F6F6B696E673F706861726D61637949643D333126506861726D6163794E616D653D25453625383125393225453625423325423025453425424125424125453625423025393125453525413425413725453825384425414625453625383825424625453525423825423825453525423725394525453525384225413425453425423825394125453525424125393726506861726D616379416464726573733D25453925393225394625453625413525424325453525384325424125453925383325424425453525423825383225453625413125383325453625424125393031254534254238253830323525323025453425424125424125453625423025393125453525413425413725453825384425414625453625383825424626426F6F6B696E67446174653D53617425323046656225323032322532303230323025323030383A35393A3535253230474D542B30383030253230284353542926757569643D356231656234643330373336646363633838643732373065333737663862643726757365724E616D653D2545352539312541382545362539382541352669644E6F3D333230343034313938343035313433343132266D6F62696C653D31333737353231373538312676657273696F6E3D346161396433303834303731333830666661386237646633313038363730313526626F6F696E67446174653D323032302D30322D323220485454502F312E310D0A486F73743A206D79637A2E6B696E67646F6E736F66742E636F6D0D0A436F6E6E656374696F6E3A206B6565702D616C6976650D0A436F6E74656E742D4C656E6774683A20320D0A4163636570743A202A2F2A0D0A4F726967696E3A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D0D0A582D5265717565737465642D576974683A20584D4C48747470526571756573740D0A417574686F72697A6174696F6E3A204D79435A20546D464F4F6A56694D5756694E47517A4D44637A4E6D526A59324D344F4751334D6A63775A544D334E325934596D51330D0A557365722D4167656E743A204D6F7A696C6C612F352E3020284C696E75783B20416E64726F696420372E303B205265646D69204E6F7465203458204275696C642F4E524439304D3B20777629204170706C655765624B69742F3533372E333620284B48544D4C2C206C696B65204765636B6F292056657273696F6E2F342E30204368726F6D652F36342E302E333238322E313337204D6F62696C65205361666172692F3533372E3336206D79637A2F312E33206B646D79637A2F312E330D0A436F6E74656E742D547970653A206170706C69636174696F6E2F6A736F6E0D0A526566657265723A20687474703A2F2F6D79637A2E6B696E67646F6E736F66742E636F6D2F6D796368616E677A686F752F4D61736B426F6F6B696E674275792F696E6465782E68746D6C0D0A4163636570742D456E636F64696E673A20677A69702C206465666C6174650D0A4163636570742D4C616E67756167653A207A682D434E2C656E2D55533B713D302E390D0A436F6F6B69653A2042494769705365727665726B6F757A616F2D6E65773D333734313832313132302E32303438302E303030303B204153502E4E45545F53657373696F6E49643D7168653276787867796E6F3377756E33686167326D7476650D0A0D0A7B7D";
            str = UtilString.HexStr2ByteArray_01(str, 20, 46);
            Console.WriteLine(str);

            //string str = "常州万仁大药房有限公司第一分公司";
            //Console.WriteLine(UtilString.EncodeZ_Utf8(str));

            //str = "钟楼区都市桃园花苑69幢101-1到121商铺";
            //Console.WriteLine(UtilString.EncodeZ_Utf8(str));


            //string str = "%E6%81%92%E6%B3%B0%E4%BA%BA%E6%B0%91%E5%A4%A7%E8%8D%AF%E6%88%BF%E5%B8%B8%E5%B7%9E%E5%8B%A4%E4%B8%9A%E5%BA%97";
            //Console.WriteLine(UtilString.DecodeZ_Utf8(str));

            //str = "%E9%92%9F%E6%A5%BC%E5%8C%BA%E9%83%BD%E5%B8%82%E6%A1%83%E6%BA%90%31%E4%B8%80%32%35%20%E4%BA%BA%E6%B0%91%E5%A4%A7%E8%8D%AF%E6%88%BF";
            //Console.WriteLine(UtilString.DecodeZ_Utf8(str));
        }


        private void Click_Algorithm(object sender, RoutedEventArgs e)
        {
            string str = @"
1	0	1	无操作	0
2	1	1	灰度变换	0
3	0	2	无操作	0
4	1	2	四边形透视变换	10
5	0	3	无操作	0
6	1	3	灰度均衡处理	0
7	0	4	无操作	0
8	1	4	中值滤波	1
9	2	4	均值滤波	4
10	3	4	高斯滤波	5
11	4	4	方框滤波	7
12	5	4	双边滤波	4
13	6	4	导向滤波	2
14	0	5	无操作	0
1002	1	5	锐化操作	9
1003	0	6	无操作	0
1004	0	7	无操作	0
1005	1	7	sobel边缘检测	4
1006	2	7	laplacian边缘检测	5
1007	3	7	canny边缘检测	4
1008	0	8	无操作	0
1009	1	8	左右邻域法	4
1010	2	8	相临边合并法	4
1011	0	9	无操作	0
1012	1	9	有煤无煤检测	2
1013	0	10	无操作	0
1014	1	10	白色腐蚀	6
1015	2	10	白色膨胀	6
1016	3	10	空洞填充	0
1018	0	11	无操作	0
1019	1	11	过曝过暗检测	8
1020	0	12	无操作	0
1021	1	12	载荷识别	5
1023	0	13	无操作	0
1024	1	13	皮带跑偏识别	20";
            str = str.Replace('\t', ',');

            Console.WriteLine(str);
        }

        /// <summary>
        /// 有时控制台输出中文的时候会有乱码，也不知上面简单的设置方式，暂时 此功能用python来做。
        /// 查到了 控制台程序的设置方式，没查到Application的WPF程序的设置方式...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Click_Sql_AlgorithmType(object sender, RoutedEventArgs e)
        {
            string str = @"
1	灰度处理	灰度处理
2	透视变换	透视变换
3	灰度均衡化	灰度均衡化
4	图像滤波	图像滤波
5	图像增强	图像增强
6	二值化处理	二值化处理
7	边缘检测	边缘检测
8	皮带煤流分离	皮带煤流分离
9	有煤无煤检测	有煤无煤检测
10	图像修整	图像修整
11	过曝过暗识别	过曝过暗识别
12	载荷识别	载荷识别
13	皮带跑偏识别	皮带跑偏识别";

            string sql1 = "insert into AlgorithmType (AlgorithmTypeID,AlgorithmTypeName,AlgorithmTypeSynopsis)values(";
            string sql2 = ");";
            string strPrint = "";
            //string[] strsRow = str.Split(new char[2] { '\r', '\n' });
            string[] strsRow = Regex.Split(str, "\r\n", RegexOptions.IgnoreCase);
            for (int i = 0; i < strsRow.Length; i++)
            {
                string strRow = strsRow[i];
                if (strRow.Trim().Length == 0)
                    continue;

                string[] strsCol = strRow.Split('\t');

                strPrint += sql1;
                strPrint += strsCol[0] + ",";
                strPrint += "'" + strsCol[1] + "',";
                strPrint += "'" + strsCol[2] + "'";
                strPrint += sql2 + "\r\n";
            }

            //你当前的是这个
            //Console.OutputEncoding = Encoding.GetEncoding(437);
            //设置成这样就支持中文编码了
            //Console.OutputEncoding = Encoding.GetEncoding(936);
            //Console.OutputEncoding = System.Text.Encoding.UTF8;//.Unicode;
            //Console.OutputEncoding = Encoding.GetEncoding("gbk");
            //Console.OutputEncoding = System.Text.Encoding.UTF8;
            //Console.OutputEncoding = Encoding.Unicode;

            Console.WriteLine(strPrint);
        }
    }
}
